from django.db import models

from django.db import models
from django.contrib.auth import get_user_model
from Shop.models import Order


class Payment(models.Model):
    # 支付id，Django会自动创建一个id字段作为主键
    order = models.OneToOneField(
        Order,
        on_delete=models.CASCADE,
        verbose_name='关联订单',
    )

    # 支付金额
    amount = models.FloatField(verbose_name='支付金额')

    # 支付状态
    status = models.CharField(
        max_length=50,
        choices=[
            ('pending', '待支付'),
            ('completed', '已完成'),
            ('failed', '支付失败'),
        ],
        default='pending',
        verbose_name='支付状态'
    )

    # 支付方式（例如信用卡、PayPal等）
    payment_method = models.CharField(max_length=100, verbose_name='支付方式')

    # 支付时间戳
    timestamp = models.DateTimeField(auto_now_add=True, verbose_name='支付时间')

    # 用户ID
    user = models.ForeignKey(
        get_user_model(),
        on_delete=models.CASCADE,
        verbose_name='用户ID',
        related_name='user_payments'
    )

    class Meta:
        verbose_name = '支付'
        verbose_name_plural = '支付'
